home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / foundation / NSValue.h < prev    next >
Text File  |  1994-05-13  |  3KB  |  74 lines

  1. /*    NSValue.h
  2.     Copyright 1994 NeXT, Inc. All rights reserved.
  3.  
  4.     Use NSValues to put random C-types into collections.
  5.     Use NSNumbers to put numbers into collections.
  6.  
  7. */
  8. #import <foundation/NSObject.h>
  9. #import <foundation/NSString.h>
  10.  
  11. /* An abstract class for wrapping any C-type with an object. Sample use: To put an NSRange into an NSArray, you would [myArray insertObject:[NSValue value:&range withObjCType:@encode(NSRange)] atIndex:n]; to get it back out, [[myArray objectAtIndex:n] getValue:&range].
  12. */
  13. @interface NSValue : NSObject <NSCopying>
  14.  
  15. + (NSValue *)value:(const void *)value withObjCType:(const char *)type;    /* Creation method */
  16.  
  17. - (void)getValue:(void *)value;    /* Value copied from the object to caller's variable... */
  18. - (const char *)objCType;    /* Standard objC encoding string */
  19.  
  20. @end
  21.  
  22.  
  23. @interface NSValue (NSValueOtherTypes)
  24.  
  25. + (NSValue *)valueWithNonretainedObject:anObject;    /* Get objects into collections without retain */
  26. - nonretainedObjectValue;
  27.  
  28. + (NSValue *)valueWithPointer:(void *)pointer;    /* Get pointers into collections */
  29. - (void *)pointerValue;
  30.  
  31. @end
  32.  
  33.  
  34. /* An abstract class for wrapping C number types with an object. NSNumbers have the added feature that they can do type-coercion. The objCType method in an NSNumber can only be one of c, C, s, S, i, I, l, L, q, Q, f, or d. 
  35. */
  36. @interface NSNumber : NSValue
  37.  
  38. + (NSNumber *)numberWithChar:(char)value;
  39. + (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
  40. + (NSNumber *)numberWithShort:(short)value;
  41. + (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
  42. + (NSNumber *)numberWithInt:(int)value;
  43. + (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
  44. + (NSNumber *)numberWithLong:(long)value;
  45. + (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
  46. + (NSNumber *)numberWithLongLong:(long long)value;
  47. + (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
  48. + (NSNumber *)numberWithFloat:(float)value;
  49. + (NSNumber *)numberWithDouble:(double)value;
  50. + (NSNumber *)numberWithBool:(BOOL)value;
  51.  
  52. /* These methods return the number in the requested type. These methods will do type-coercion as defined by C. In certain cases the results may be undefined; for instance, trying to take the unsigned integer value of a negative number, or trying to get the short value of an float which is greater than the maximum short.
  53. */
  54. - (char)charValue;
  55. - (unsigned char)unsignedCharValue;
  56. - (short)shortValue;
  57. - (unsigned short)unsignedShortValue;
  58. - (int)intValue;
  59. - (unsigned int)unsignedIntValue;
  60. - (long)longValue;
  61. - (unsigned long)unsignedLongValue;
  62. - (long long)longLongValue;
  63. - (unsigned long long)unsignedLongLongValue;
  64. - (float)floatValue;
  65. - (double)doubleValue;
  66. - (BOOL)boolValue;
  67. - (NSString *)stringValue;
  68.  
  69. /* Compare the numbers exactly like C would.
  70. */
  71. - (NSComparisonResult)compare:(NSNumber *)otherNumber;
  72. @end
  73.  
  74.